clear all
set more off

use "$inputs/prowess/Raw Materials Consumed.dta"
drop if rawmat_consump_val11 < 0 | rawmat_consump_qty8 < 0

* standardize units for raw material
rename rawmat_consump_unit10 unit1
replace unit1 = upper(unit1)
merge m:1 unit1 using "$inputs/handcoded/unit_conversion.dta"
keep if _merge ==3
drop _merge unit1
rename unit rawmat_unit
rename conversion rawmat_conversion
gen rawmat_consump_qty = rawmat_consump_qty8 * rawmat_conversion

gen rawmat_price = rawmat_consump_val11/rawmat_consump_qty
bys rawmater_cocode1 rawmat_date3: egen tot_rawmat_value = total(rawmat_consump_val11)
gen rawmat_value_share = rawmat_consump_val11 / tot_rawmat_value

gen log_rawmat_price = log(rawmat_price / rawmat_value_share)
gen log_rawmat_price_index = rawmat_value_share * log_rawmat_price
collapse (sum) log_rawmat_price_index rawmat_consump_val11, by(rawmater_cocode1 rawmat_date3)

rename rawmater_cocode1 products_cocode1 
rename rawmat_date3 prod_date3
save "$working/rawmat.dta", replace
